﻿using System;

namespace Sigil.Impl
{
	internal sealed class PrefixTracker
	{
		public Boolean HasUnaligned { get; private set; }

		public Int32? Unaligned { get; private set; }

		public Boolean HasVolatile { get; private set; }

		public Boolean HasReadOnly { get; private set; }

		public Boolean HasTailCall { get; private set; }

		public Boolean HasConstrained { get; private set; }

		public Type Constrained { get; private set; }

		public void SetUnaligned(Int32 a)
		{
			HasUnaligned = true;
			Unaligned = a;
		}

		public void SetVolatile()
		{
			HasVolatile = true;
		}

		public void SetReadOnly()
		{
			HasReadOnly = true;
		}

		public void SetTailCall()
		{
			HasTailCall = true;
		}

		public void SetConstrained(Type t)
		{
			HasConstrained = true;
			Constrained = t;
		}

		public void Clear()
		{
			HasUnaligned = false;
			Unaligned = -1;
			HasVolatile = false;
			HasReadOnly = false;
			HasConstrained = false;
			Constrained = null;
		}

		public PrefixTracker Clone()
		{
			return
					new PrefixTracker
					{
						Constrained = Constrained,
						HasConstrained = HasConstrained,
						HasReadOnly = HasReadOnly,
						HasTailCall = HasTailCall,
						HasUnaligned = HasUnaligned,
						HasVolatile = HasVolatile,
						Unaligned = Unaligned
					};
		}
	}
}